#include "stdafx.h"
#include "util.h"

#pragma warning(disable : 4996)

namespace shared
{
    std::string QOther::FormatBytes(double bytes)
    {
        char buf[32] = {};
        if (bytes < 1024 * 1024)
            sprintf(buf, "%.2fKB", bytes / 1024);
        else if (bytes < 1024 * 1024 * 1024)
            sprintf(buf, "%.2fMB", bytes / 1024 / 1024);
        else
            sprintf(buf, "%.2fGB", bytes / 1024 / 1024 / 1024);
        return buf;
    }

    std::string FormatBps(double bytes)
    {
        double bits = bytes * 8;
        char buf[32] = {};
        if (bits < 100000)
            sprintf(buf, "%dbps", (int)bits);
        else if (bits < 1024 * 1024)
            sprintf(buf, "%dKbps", (int)bits / 1024);
        else if (bits < 1024 * 1024 * 1024)
            sprintf(buf, "%.2fMbps", bits / 1024 / 1024);
        else
            sprintf(buf, "%.2fGbps", bits / 1024 / 1024 / 1024);
        return buf;
    }
}